home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Interplay's Learn to Program Basic (Review Copy)
/
Learn to Program Basic Review Copy (Interplay)(June 23, 1998).ISO
/
pc
/
ltpbasic
/
projects
/
eliza.bas
< prev
next >
Wrap
BASIC Source File
|
1998-02-21
|
8KB
|
314 lines
Rem ---------------------
Rem Eliza
Rem
Rem Concept based upon the
Rem original ELIZA developed
Rem by Joseph Weizenbaum of MIT
Rem
Rem ----------------------
Rem ----------------
Rem Initialize the data
Rem ----------------
numkeys = 0
numswaps = 0
numReplies = 0
Read NumKeys
Read NumSwaps
Read NumReplies
REM *** DIM BUG -- Won't Take Variable!
Dim Keyword$(NumKeys)
Dim Swap$(NumSwaps)
Dim Reply$(NumReplies)
Dim ReplyIndex(NumKeys)
Dim ReplyNum(NumKeys)
Dim NextReply(NumKeys)
For i = 1 to NumKeys
Read Keyword$(i)
Next i
For i = 1 to NumSwaps
Read Swap$(i)
Next i
For i = 1 to NumReplies
Read Reply$(i)
Next i
For i = 1 to NumKeys
Read ReplyIndex(i)
Read ReplyNum(i)
NextReply(i) = 0
Next i
Rem -----------------------
Rem Clear screen and show starting banner
Rem -----------------------
Start:
CLS
DrawText "@Color 100,32,Bold,Times@Eliza" AT 125,10
Textcolor 67 'Royal Blue
Print
Print
Print
Print "Hello. I am Eliza, the psychoanalytical"
Print "computer program. Please state the"
Print "nature of your psychological problem."
LastI$ = ""
Rem -----------------------------
Rem Get User Input
Rem -----------------------------
UserInput:
TextColor 21
Print
Input ">> ",I$
' If we end in a ? or a . then strip this.
If Right$(I$,1) = "?" OR Right$(I$,1) = "." OR Right$(I$,1) = "!" Then
I$ = Left$(I$,Len(I$)-1)
EndIf
' Make it all upper case!
I$ = " "+Upper$(I$)+" "
' Get rid of any input apostrophes
L = InStr(I$,"'")
While L>0
I$ = Left$(I$,L-1)+Right$(I$,Len(I$)-L)
L = InStr(I$,"'")
Wend
Rem -- Look for special types of input
If I$ = LastI$ Then
Print "PLEASE, DON'T REPEAT YOURSELF."
LastI$ = ""
Goto UserInput
EndIf
If InStr(I$," GOODBYE ") THEN
Print "GOODBYE. THANK YOU FOR TALKING."
Print
Sleep 20
Goto Start
EndIf
LastI$ = I$
Rem ---------------------------
Rem Look for a keyword in input
Rem ---------------------------
For key = 1 to NumKeys
L = InStr(I$,keyword$(key))
If L>0 Then Goto FoundKey
Next key
key = NumKeys
FoundKey:
If key < NuMKeys Then
F$ = keyword$(key)
Else
F$ = ""
Endif
Rem ----------------------------
Rem Now, take the right side
Rem of the string and swap
Rem the subject / object words
Rem ----------------------------
R$ = Right$(I$,Len(I$)-Len(F$)-L+1)+" "
For s = 1 to NumSwaps Step 2
w = InStr(R$,swap$(s))
while w>0
R$ = Left$(R$,w-1)+swap$(s+1)+Right$(R$,Len(R$)-(w+len(swap$(s))))
w = InStr(R$,swap$(s))
wend
Next s
Rem -- Now, remove extraneous characters
For i = 1 To Len(R$)-1
If Mid$(R$,i,1) = "!" Then
R$ = Left$(R$,i-1)+Right$(R$,Len(R$)-i)
EndIf
If Mid$(R$,i,1) = " " AND Mid$(R$,i+1,1) = " " Then
R$ = Left$(R$,i-1)+Right$(R$,Len(R$)-i)
EndIf
Next i
Rem ---------------------------
Rem Now, choose a reply based
Rem upon the keyword we found
Rem and print it out
Rem ---------------------------
reply = ReplyIndex(key) + NextReply(key)
NextReply(key) = NextReply(key)+1
if NextReply(key) >= ReplyNum(key) Then NextReply(key) = 0
Rep$ = Reply$(reply)
TextColor 67 'Royal Blue
' If the reply is meant to, then echo back the question as part of the answer
If Right$(Rep$,1) = "*" Then
Print Left$(Rep$,Len(Rep$)-1)+" "+R$
Else
Print Rep$
Endif
Rem Now, do it again!
Goto UserInput
Rem %%%%%%%%%%%%%%%%%%%%%%%%%%%%
Rem Program Data
Rem %%%%%%%%%%%%%%%%%%%%%%%%%%%%
Data 36 ' Number of Keywords
Data 14 ' Number of 'swap' words (both)
Data 112 ' Number of replies
Rem Keywords
DATA " CAN YOU "," CAN I "," YOU ARE ", " YOURE "," I DONT "," I FEEL "
DATA " WHY DONT YOU "," WHY CANT I "," ARE YOU "," I CANT "," I AM "," IM "
DATA " YOU "," I WANT "," WHAT "," HOW "," WHO "," WHERE "," WHEN "," WHY "
DATA " NAME "," CAUSE "," SORRY "," DREAM "," HELLO "," HI "," MAYBE "
DATA " NO "," YOUR "," ALWAYS "," THINK "," ALIKE "," YES "," FRIEND "
DATA " COMPUTER ","-NOKEY-"
Rem Swap words
DATA " ARE "," AM ","WERE ","WAS "," YOU "," I ","YOUR ","MY "
DATA " IVE "," YOUVE "," IM " ," YOURE "
DATA " ME "," !YOU "
Rem Replies
DATA "DONT YOU BELIEVE THAT I CAN*"
DATA "PERHAPS YOU WOULD LIKE TO BE ABLE TO*"
DATA "YOU WANT ME TO BE ABLE TO*"
DATA "PERHAPS YOU DON'T WANT TO*"
DATA "DO YOU WANT TO BE ABLE TO*"
DATA "WHAT MAKES YOU THINK I AM*"
DATA "DOES IT PLEASE YOU TO BELIEVE I AM*"
DATA "PERHAPS YOU WOULD LIKE TO BE*"
DATA "DO YOU SOMETIMES WISH YOU WERE*"
DATA "DON'T YOU REALLY*"
DATA "WHY DON'T YOU*"
DATA "DO YOU WISH TO BE ABLE TO*"
DATA "DOES THAT TROUBLE YOU?"
DATA "TELL ME MORE ABOUT SUCH FEELINGS."
DATA "DO YOU OFTEN FEEL*"
DATA "DO YOU ENJOY FEELING*"
DATA "DO YOU REALLY BELIEVE I DON'T*"
DATA "PERHAPS IN GOOD TIME I WILL*"
DATA "DO YOU WANT ME TO*"
DATA "DO YOU THINK YOU SHOULD BE ABLE TO*"
DATA "WHY CAN'T YOU*"
DATA "WHY ARE YOU INTERESTED IN WHETHER OR NOT I AM*"
DATA "WOULD YOU PREFER IF I WERE NOT*"
DATA "PERHAPS IN YOUR FANTASIES I AM*"
DATA "HOW WOULD YOU KNOW YOU CAN'T*"
DATA "HAVE YOU TRIED?"
DATA "PERHAPS YOU CAN NOW*"
DATA "DID YOU COME TO ME BECAUSE YOU ARE*"
DATA "HOW LONG HAVE YOU BEEN*"
DATA "DO YOU BELIEVE IT IS NORMAL TO BE*"
DATA "DO YOU ENJOY BEING*"
DATA "WE WERE DISCUSSING YOU - NOT ME."
DATA "OH, I*"
DATA "YOU'RE NOT REALLY TALKING ABOUT ME, ARE YOU?"
DATA "WHAT WOULD IT MEAN TO YOU IF YOU GOT*"
DATA "WHY DO YOU WANT*"
DATA "SUPPOSE YOU SOON GOT*"
DATA "WHAT IF YOU NEVER GOT*"
DATA "I SOMETIMES ALSO WANT*"
DATA "WHY DO YOU ASK?"
DATA "DOES THAT QUESTION INTEREST YOU?"
DATA "WHAT ANSWER WOULD PLEASE YOU THE MOST?"
DATA "WHAT DO YOU THINK?"
DATA "ARE SUCH QUESTIONS ON YOUR MIND OFTEN?"
DATA "WHAT IS IT THAT YOU REALLY WANT TO KNOW?"
DATA "HAVE YOU ASKED ANYONE ELSE?"
DATA "HAVE YOU ASKED SUCH QUESTIONS BEFORE?"
DATA "WHAT ELSE COMES TO MIND WHEN YOU ASK THAT?"
DATA "NAMES DON'T INTEREST ME."
DATA "I DON'T CARE ABOUT NAMES - PLEASE GO ON."
DATA "IS THAT THE REAL REASON?"
DATA "DON'T ANY OTHER REASONS COME TO MIND?"
DATA "DOES THAT REASON EXPLAIN ANYTHING ELSE?"
DATA "WHAT OTHER REASONS MIGHT THERE BE?"
DATA "PLEASE DON'T APOLOGIZE!"
DATA "APOLOGIES ARE NOT NECESSARY."
DATA "WHAT FEELINGS DO YOU HAVE WHEN YOU APOLOGIZE?"
DATA "DON'T BE SO DEFENSIVE!"
DATA "WHAT DOES THAT DREAM SUGGEST TO YOU?"
DATA "DO YOU DREAM OFTEN?"
DATA "WHAT PERSONS APPEAR IN YOUR DREAMS?"
DATA "ARE YOU DISTURBED BY YOUR DREAMS?"
DATA "HOW DO YOU DO...PLEASE STATE YOUR PROBLEM."
DATA "YOU DON'T SEEM QUITE CERTAIN."
DATA "WHY THE UNCERTAIN TONE?"
DATA "CAN'T YOU BE MORE POSITIVE?"
DATA "YOU AREN'T SURE?"
DATA "DON'T YOU KNOW?"
DATA "ARE YOU SAYING NO JUST TO BE NEGATIVE?"
DATA "YOU ARE BEING A BIT NEGATIVE."
DATA "WHY NOT?"
DATA "ARE YOU SURE?"
DATA "WHY NO?"
DATA "WHY ARE YOU CONCERNED ABOUT MY*"
DATA "WHAT ABOUT YOUR OWN*"
DATA "CAN YOU THINK OF A SPECIFIC EXAMPLE?"
DATA "WHEN?"
DATA "WHAT ARE YOU THINKING OF?"
DATA "REALLY, ALWAYS?"
DATA "DO YOU REALLY THINK SO?"
DATA "BUT YOU ARE NOT SURE YOU*"
DATA "DO YOU DOUBT YOU*"
DATA "IN WHAT WAY?"
DATA "WHAT RESEMBLENCE DO YOU SEE?"
DATA "WHAT DOES THE SIMILARITY SUGGEST TO YOU?"
DATA "WHAT OTHER CONNECTIONS DO YOU SEE?"
DATA "COULD THERE REALLY BE SOME CONNECTION?"
DATA "HOW?"
DATA "YOU SEEM QUITE POSITIVE."
DATA "ARE YOU SURE?"
DATA "I SEE."
DATA "I UNDERSTAND."
DATA "WHY DO YOU BRING UP THE TOPIC OF FRIENDS?"
DATA "DO YOUR FRIENDS WORRY YOU?"
DATA "DO YOUR FRIENDS PICK ON YOU?"
DATA "ARE YOU SURE YOU HAVE ANY FRIENDS?"
DATA "DO YOU IMPOSE ON YOUR FRIENDS?"
DATA "PERHAPS YOUR LOVE FOR FRIENDS WORRIES YOU."
DATA "DO COMPUTERS WORRY YOU?"
DATA "ARE YOU TALKING ABOUT ME IN PARTICULAR?"
DATA "ARE YOU FRIGHTENED BY MACHINES?"
DATA "WHY DO YOU MENTION COMPUTERS?"
DATA "WHAT DO YOU THINK MACHINES HAVE TO DO WITH YOU PROBLEM?"
DATA "DON'T YOU THINK COMPUTERS CAN HELP PEOPLE?"
DATA "WHAT IS IT ABOUT MACHINES THAT WORRIES YOU?"
DATA "SAY, DO YOU HAVE ANY PSYCHOLOGICAL PROBLEMS?"
DATA "WHAT DOES THAT SUGGEST TO YOU?"
DATA "I SEE."
DATA "I'M NOT SURE I UNDERSTAND YOU FULLY."
DATA "COME, COME, ELUCIDATE YOUR THOUGHTS."
DATA "CAN YOU ELABORATE ON THAT?"
DATA "THAT IS QUITE INTERESTING"
Rem Indexes into replies:
Rem Data read in pairs, one for each keyword.
Rem The first number of the pair
Rem is the starting index for a reply
Rem and the next number is the number
Rem of possible replies.
DATA 1,3,4,2,6,4,6,4,10,4,14,3,17,3,20,2,22,3,25,3
DATA 28,4,28,4,32,3,35,5,40,9,40,9,40,9,40,9,40,9,40,9
DATA 49,2,51,4,55,4,59,4,63,1,63,1,64,5,69,5,74,2,76,4
DATA 80,3,83,7,90,3,93,6,99,7,106,6